<template>
  <el-container>
    <el-header>
      <!-- logo盒子 -->
      <div class="logo">
        <img src="../../assets/imgs/avater.png" alt="">
        <span class="title">科泰新冠物资管理系统</span>
      </div>
      <!-- 登录注销等操作的盒子 -->
      <div class="operation">
        <el-dropdown trigger="click" @command="handleCommand">
          <img src="../../assets/imgs/avater.png" alt="">
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-house">首页</el-dropdown-item>
            <el-dropdown-item icon="el-icon-switch-button" command="logout">注销</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <el-row class="tac">
          <el-col>
            <span @click="isCollapse = !isCollapse" class="collapse">|||</span>
            <el-menu
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose"
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
                style="border: none"
                router
                :collapse="isCollapse"
                :collapse-transition="false"
                :unique-opened="true">
              <SideMenu :menuList="menuList"></SideMenu>
            </el-menu>
          </el-col>
        </el-row>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
//导入组件
import {findMenuInfo} from "../../api";
import SideMenu from "../../views/Home/SideMenu";

export default {
  name: 'index',
  components: {
    //注册组件
    SideMenu,
  },
  data() {
    return {
      isCollapse: false,
      menuList: [], // 菜单列表
    }
  },
  created() {
    this.findMenuInfo();
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    // 退出登录
    async handleCommand(command) {
      if (command == "logout") {
        var res = await this.$confirm("此操作将退出系统, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出登入"
          });
        });
        if (res == "confirm") {
          //清除vuex中的数据
          this.$store.commit("clearUserInfo")
          window.localStorage.clear();
          this.$router.push("/login");
        }
      }
    },
    // 左边菜单栏列表
    findMenuInfo() {
      findMenuInfo().then((res) => {
        console.log(res)
        this.menuList = res.data.menus;
      })
    },
  }
}
</script>

<style lang="less" scoped>
img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin: 0px 20px;
}

.el-container {
  height: 100%;
}

.el-header {
  background-color: #B3C0D1;
  display: flex;
  justify-content: space-between;

  .logo {
    display: flex;
    align-items: center;

    .title {
      font-size: 30px;
      color: pink;
    }
  }
}

.el-aside {
  background-color: #D3DCE6;
}

.el-main {
  background-color: #E9EEF3;
}

.collapse {
  background-color: orange;
  color: black;
  display: inline-block;
  width: 100%;
  height: 30px;
  text-align: center;
  line-height: 30px;
  font-size: 20px;
  font-weight: bolder;
  cursor: pointer;
}


</style>